<?php

namespace Applications\Frontoffice\Modules\Connexion;

class ConnexionController extends \Library\BackController {

    public function executeLogin(\Library\HTTPRequest $request) {
        $this->page->addVar('title', 'Connexion');
        // On récupère le manager des chaines
        $manager = $this->managers->getManagerOf('Connexion');
 
        if ($request->postExists('username')) {
            $login = $request->postData('username');
            $password = $request->postData('password');
            if ($manager->checkAuth($login, $password) == true){
                $this->app->user()->setAuthenticated(true);
                $this->app->user()->setName($login);
                $this->app->httpResponse()->redirect('.');
            }
            else {
                $this->app->user()->setFlash('Le pseudo/mdp est incorrect');
            }
        }
    }
    
    public function executeLogout(\Library\HTTPRequest $request) {
        $this->app->user()->setAuthenticated(false);
        $this->app->httpResponse()->redirect('.');
    }
}

?>
